// models/User.js
const pool = require('../db');

class User {
  static async findByPk(id) {
    const [rows] = await pool.query('SELECT * FROM Users WHERE id = ?', [id]);
    return rows[0];
  }

  static async findByUsername(username) {
    const [rows] = await pool.query('SELECT * FROM Users WHERE username = ?', [username]);
    return rows[0];
  }

  static async create(user) {
    const [result] = await pool.query('INSERT INTO Users (username, password, email) VALUES (?, ?, ?)', [user.username, user.password, user.email]);
    return result.insertId;
  }
}

module.exports = User;